package com.lk.ii.controller;

import java.util.List;

import com.lk.framework.util.ShiroUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.lk.common.annotation.Log;
import com.lk.common.enums.BusinessType;
import com.lk.ii.domain.IiRecommendMaterial;
import com.lk.ii.service.IIiRecommendMaterialService;
import com.lk.common.core.controller.BaseController;
import com.lk.common.core.domain.AjaxResult;
import com.lk.common.utils.poi.ExcelUtil;
import com.lk.common.core.page.TableDataInfo;

/**
 * 推荐位详情Controller
 * 
 * @author lk
 * @date 2021-02-05
 */
@Controller
@RequestMapping("/ii/recommend_material")
public class IiRecommendMaterialController extends BaseController
{
    private String prefix = "ii/recommend_material";

    @Autowired
    private IIiRecommendMaterialService iiRecommendMaterialService;

    @RequiresPermissions("ii:recommend_material:view")
    @GetMapping("/index/{recommendId}")
    public String recommend_material(@PathVariable("recommendId") Long recommendId,ModelMap mmap)
    {
        mmap.put("recommendId", recommendId);
        return prefix + "/recommend_material";
    }

    /**
     * 查询推荐位详情列表
     */
    @RequiresPermissions("ii:recommend_material:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(IiRecommendMaterial iiRecommendMaterial)
    {
        startPage();
        List<IiRecommendMaterial> list = iiRecommendMaterialService.selectIiRecommendMaterialList(iiRecommendMaterial);
        return getDataTable(list);
    }

    /**
     * 导出推荐位详情列表
     */
    @RequiresPermissions("ii:recommend_material:export")
    @Log(title = "推荐位详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(IiRecommendMaterial iiRecommendMaterial)
    {
        List<IiRecommendMaterial> list = iiRecommendMaterialService.selectIiRecommendMaterialList(iiRecommendMaterial);
        ExcelUtil<IiRecommendMaterial> util = new ExcelUtil<IiRecommendMaterial>(IiRecommendMaterial.class);
        return util.exportExcel(list, "recommend_material");
    }

    /**
     * 新增推荐位详情
     */
    @GetMapping("/add/{recommendId}")
    public String add(@PathVariable("recommendId") Long recommendId,ModelMap mmap)
    {
        mmap.put("recommendId", recommendId);
        return prefix + "/add";
    }

    /**
     * 新增保存推荐位详情
     */
    @RequiresPermissions("ii:recommend_material:add")
    @Log(title = "推荐位详情", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(IiRecommendMaterial iiRecommendMaterial)
    {
        iiRecommendMaterial.setCreateBy(ShiroUtils.getLoginName());
        return toAjax(iiRecommendMaterialService.insertIiRecommendMaterial(iiRecommendMaterial));
    }

    /**
     * 修改推荐位详情
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        IiRecommendMaterial iiRecommendMaterial = iiRecommendMaterialService.selectIiRecommendMaterialById(id);
        mmap.put("iiRecommendMaterial", iiRecommendMaterial);
        return prefix + "/edit";
    }

    /**
     * 修改保存推荐位详情
     */
    @RequiresPermissions("ii:recommend_material:edit")
    @Log(title = "推荐位详情", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(IiRecommendMaterial iiRecommendMaterial)
    {
        iiRecommendMaterial.setUpdateBy(ShiroUtils.getLoginName());
        return toAjax(iiRecommendMaterialService.updateIiRecommendMaterial(iiRecommendMaterial));
    }

    /**
     * 删除推荐位详情
     */
    @RequiresPermissions("ii:recommend_material:remove")
    @Log(title = "推荐位详情", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(iiRecommendMaterialService.deleteIiRecommendMaterialByIds(ids));
    }
}
